// pages/my/printOut/printOut.js
const utils = require("../../../utils/utils.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page:1,
    pageNum:10,
    firstOpen:0
  },
  getIndex(){
    var that = this;
    utils.request('refund/lists',{page:that.data.page,limit:that.data.pageNum}, function (res) {
      wx.stopPullDownRefresh();
      if (res.data.code == 200) {
        if (that.data.page == 1) {
            that.setData({
                page: res.data.data.page,
                pageCount: res.data.data.pageCount,
                list:res.data.data.rows
            })
        } else {
            var array = that.data.list;
            var listArray = array.concat(res.data.data.rows)
            that.setData({
                page: res.data.data.page,
                pageCount: res.data.data.pageCount,
                list: listArray
            })
        }
      } else {
        wx.hideLoading()
        utils.toast(res.data.msg)
      }
    })
  },
  goInvoice(){
    wx.navigateTo({
      url: '/pages/my/invoice/invoice?id=0',
    })
  },
  goUrl(e){
    var code = e.currentTarget.dataset.code;
    wx.navigateTo({
      url: '../refundDetail/refundDetail?id='+code,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getIndex()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    if (that.data.firstOpen == 1) {
      this.getIndex()
    } else {
      that.setData({
        firstOpen: 1
      })
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.setData({
        page: 1
    })
    this.getIndex();
    wx.stopPullDownRefresh()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (this.data.page == this.data.pageCount) {
        return false;
    } else {
        var page = parseInt(this.data.page) + 1
        this.setData({
            page: page
        })
        this.getIndex();
    }
  }
})